package Interface.lianxi08;

import javax.imageio.plugins.jpeg.JPEGQTable;

abstract  class Animal{
    public abstract  void eat();
}
interface  Pet{
    void play();
}
class Dog extends  Animal implements  Pet{

    @Override
    public void eat() {
        System.out.println("Dog eat Bones");
    }

    @Override
    public void play() {
        System.out.println("Play with Dog");
    }
}
class  Cat extends  Animal implements  Pet{

    @Override
    public void eat() {
        System.out.println("Cat eat fish");
    }

    @Override
    public void play() {
        System.out.println("Play with Cat");
    }
}
class  Wolf extends  Animal{

    @Override
    public void eat() {
        System.out.println("Wolf eat meat");
    }
}
public class TestInterface {
    public static void main(String[] args) {
        Animal[] animals = new Animal[3];
        animals[0]=new Dog();
        animals[1]=new Cat();
        animals[2]=new Wolf();
        //调用数组中所有动物的eat方法
        for (int i = 0; i <animals.length ; i++) {
          animals[i].eat();

        }
        //2.调用数组中所有宠物的play方法
        for (int i = 0; i <animals.length ; i++) {
            if (animals[i] instanceof Pet)  {
            Pet pet =(Pet) animals[i];
            pet.play();
            }
        }
    }
}
